<?php
/**
 * 对服务器的进程进行监控
 * Class Server
 */
class Server
{
    const PORT = 8811;
    public function port()
    {
        //编写要执行的shell命令
        $shell = 'netstat -anp | grep '.self::PORT . ' | grep LISTEN | wc -l';
        $result = shell_exec($shell);
        if($result != 1){
            echo date('Y-m-d H:i:s').' error'.PHP_EOL;
        }else{
            echo date('Y-m-d H:i:s').' success'.PHP_EOL;
        }
    }
}
swoole_timer_tick(2000,function($timer_id){
    (new Server())->port();
    echo 'time-start'.PHP_EOL;
});

new Server();